<template>
    <div class="user-main">
        <div class="content" v-if="!toExamisShow">
            <el-card class="box-card" shadow="never">
                <el-row style="display: flex;justify-content: space-between">
                    <el-col :span="10">
                        <div style="height: 100%;display: flex;flex-direction: column;justify-content: space-between">
                            <el-card shadow="never">
                                <div slot="header" class="clearfix">
                                    <i class="iconfont icon-youkexinxi-"></i>
                                    <span style="font-weight: 600;font-size: 17px">个人信息</span>
                                </div>
                                <div class="left-content">
                                    <el-row style="display: flex;justify-content: space-around;align-items: center">
                                        <el-col :span="6">
                                            <div class="block">
                                                <el-avatar shape="square" :size="100" :src="person.photo"></el-avatar>
                                            </div>
                                        </el-col>
                                        <el-col :span="18">
                                            <div shadow="never" class="person-content">
                                                <p><i class="el-icon-user-solid"></i>:{{person.name}} <i
                                                        class="iconfont icon-xingbie"></i>:{{person.gender_display}}</p>
                                                <p><i class="iconfont icon-zhengjianleixing"></i>:{{person.card_type_display}}
                                                </p>
                                                <p><i class="iconfont icon-cardid"></i>:{{person.card_id}}</p>
                                                <p><i class="iconfont icon-date"></i>:{{person.birthday}}</p>
                                            </div>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <div class="person-address">
                                                <i class="iconfont icon-city"></i>:{{person.address}}
                                            </div>
                                        </el-col>
                                    </el-row>
                                </div>
                            </el-card>
                            <el-card shadow="never">
                                <el-card shadow="never" class="school-content">
                                    <p>学校:<span v-if="person.state_code > 7">{{person.school}}</span><span v-else>---</span></p>
                                    <p>专业:<span v-if="person.state_code > 7">{{person.major}}</span><span v-else>---</span> 学历:<span
                                            v-if="person.state_code > 7">{{person.hig_edu}}</span><span v-else>---</span></p>
                                    <p>毕业时间:<span v-if="person.state_code > 7">{{person.grad_time}}</span><span v-else>---</span></p>
                                </el-card>
                                <el-card shadow="never" class="school-content">
                                    <p>单位:<span v-if="person.state_code > 7">{{person.com_name}}</span><span v-else>---</span></p>
                                    <p>工作年限:<span v-if="person.state_code > 7">{{person.work_age}}</span><span v-else>---</span>年</p>
                                    <p>职务:<span v-if="person.state_code > 7">{{person.work_duty}}</span><span v-else>---</span></p>
                                    <p>职称资格技能:<span v-if="person.state_code > 7">{{person.work_title}}</span><span v-else>---</span></p>
                                    <p>邮箱:<span v-if="person.state_code > 7">{{person.email}}</span><span v-else>---</span></p>
                                </el-card>
                            </el-card>
                        </div>
                    </el-col>
                    <el-col :span="13">
                        <el-card shadow="never">
                            <div slot="header" class="clearfix">
                                <span style="font-size: 17px;font-weight: 600;">报考信息</span>
                                <el-button style="float: right; padding: 3px 0" type="text"
                                           @click="registerVisible = true">添加报名
                                </el-button>
                            </div>
                            <el-dialog
                                    title="新建报名"
                                    :visible.sync="registerVisible"
                                    width="50%"
                                    :before-close="addRegisterClose">
                                <register-form :isNotFirstRegister="true" @registerForm="get_n_Org"
                                               :registerParams="profile" style="text-align: left"></register-form>
                            </el-dialog>
                            <el-scrollbar style="height: calc(100vh - 300px)">
                                <div class="right-content">
                                    <el-card v-for="item in profile" shadow="never" class="exam-content" :key="item.id">
                                        <div slot="header" class="clearfix">
                                            <span>{{item.course.name}}</span>
                                            <el-button :disabled="item.state_code < 3||(item.state_code < 7 && item.exam_date) ? false : true"
                                                       style="float: right;" size="mini"
                                                       @click="updateExam(item.id)">编辑
                                            </el-button>
                                        </div>
                                        <div class="exam-text">
                                            <p>考试机构:{{item.org.org_name}}</p>
                                            <p>姓名:{{item.name}}</p>
                                            <p>报考科目:{{item.course.name}}</p>
                                            <p>是否购书:
                                                <el-tag size="mini">{{item.buy_book ? '是':'否'}}</el-tag>
                                            </p>
                                            <p>是否参加培训:
                                                <el-tag size="mini">{{item.is_train ? '是':'否'}}</el-tag>
                                            </p>
                                            <p>激活日期:{{item.active_date}}</p>
                                            <p>账号到期:{{item.exp_date}}</p>
                                            <p>考试地点:{{item.exam_city}}</p>
                                            <p>考试时间:{{item.exam_date}}</p>
                                            <p>审核状态:{{state_map[item.state_code]}}</p>
<!--                                            <p>{{item.exam_list[item.exam_list.length-1]['is_pass'] === false}}</p>-->
                                        </div>
                                        <div v-if="(!item.school && !item.exam_date)||(item.exam_list[item.exam_list.length-1]&&item.exam_list[item.exam_list.length-1]['is_pass']===false)"
                                             style="width: 100%;display: flex;justify-content: flex-end;padding-top: 10px">
                                            <el-button size="mini" @click="toExam(item.id)">{{(item.exam_list[item.exam_list.length-1]&&item.exam_list[item.exam_list.length-1]['is_pass']===false) ? '点击补考':'点击报考'}}</el-button>
                                        </div>
                                    </el-card>
                                </div>
                            </el-scrollbar>
                        </el-card>
                    </el-col>
                </el-row>
            </el-card>
            <el-drawer
                    title="编辑信息"
                    size="50%"
                    :visible.sync="drawer"
                    :direction="direction"
                    :before-close="ExamhandleClose">
                <el-card style="text-align: left">
                    <el-form ref="form" :model="form" label-width="80px">
                        <div>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="姓名:">
                                        <el-input :disabled="userDisable" v-model="form.name"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="性别:">
                                        <el-radio-group :disabled="userDisable" v-model="form.gender">
                                            <el-radio label="m">男</el-radio>
                                            <el-radio label="f">女</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <el-form-item label="出生日期:">
                                        <!--                                        <el-input v-model="form.birthday"></el-input>-->
                                        <el-date-picker :disabled="userDisable" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"
                                                        placeholder="选择日期" v-model="form.birthday"
                                                        style="width: 100%;"></el-date-picker>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="证件类型:">
                                        <el-select :disabled="userDisable" v-model="form.card_type" placeholder="请选择证件类型">
                                            <el-option v-for="item in cardOptions" :key="item.id" :label="item.name"
                                                       :value="item.id"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="证件号码:">
                                        <el-input :disabled="userDisable" v-model="form.card_id"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="手机号码:">
                                        <el-input v-model="form.phone"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <el-form-item label="邮箱:">
                                        <el-input :disabled="userDisable" v-model="form.email"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="是否购书:">
                                        <el-switch v-model="form.buy_book" active-text="是" inactive-text="否">
                                        </el-switch>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="9">
                                    <el-form-item label="考试城市:">
                                        <!--                                        <el-input v-model="form.exam_city"></el-input>-->
                                        <el-select v-model="form.exam_city" placeholder="请选择证件类型">
                                            <el-option v-for="item in courseList" :key="item"
                                                       :label="item"
                                                       :value="item"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="单位:">
                                        <el-input v-model="form.com_name"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="9">
                                    <el-form-item label="职务:">
                                        <el-input v-model="form.work_duty"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="现居省份:">
                                        <el-cascader
                                                size="large"
                                                :options="areaOptions"
                                                v-model="selectedOptions"
                                                @change="addressChange">
                                        </el-cascader>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="详细地址:">
                                        <el-input type="textarea" autosize v-model="form.address"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </div>
                        <div v-show="form.state_code >= 4">
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="姓拼音:">
                                        <el-input v-model="form.first_py"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item label="名拼音:">
                                        <el-input v-model="form.last_py"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="毕业学校:">
                                        <el-input v-model="form.school"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <el-form-item label="毕业时间:">
                                        <el-date-picker format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"
                                                        placeholder="选择日期" v-model="form.grad_time"
                                                        style="width: 100%;"></el-date-picker>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="10">
                                    <el-form-item label="最高学历:">
                                        <el-select v-model="form.hig_edu" placeholder="最高学历">
                                            <el-option label="硕士研究生" value="硕士研究生"></el-option>
                                            <el-option label="博士" value="博士"></el-option>
                                            <el-option label="本科" value="本科"></el-option>
                                            <el-option label="大专" value="大专"></el-option>
                                            <el-option label="中专/职技校" value="中专/职技校"></el-option>
                                            <el-option label="高中" value="高中"></el-option>
                                            <el-option label="其他" value="其他"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="专业门类:">
                                        <el-input v-model="form.major"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="10">
                                    <el-form-item label="单位名称:">
                                        <el-input v-model="form.com_name"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item label="从业年限:">
                                        <el-input type="number" v-model="form.work_age"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="10">
                                    <el-form-item label="现有职称:">
                                        <el-input v-model="form.work_title"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <el-form-item label="现有职务:">
                                        <el-input v-model="form.work_duty"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="10">
                                    <el-form-item label="职务英文:">
                                        <el-input v-model="form.work_duty_en"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="是否购书:">
                                        <el-switch v-model="form.buy_book" active-text="是" inactive-text="否">
                                        </el-switch>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="10">
                                    <el-form-item label="证件照:">
                                        <img-upload :url="form.photo" @upload="updateUpload"></img-upload>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <!--                                    <el-form-item label="激活日期">-->
                                    <!--                                        <el-input v-model="form.active_date"></el-input>-->
                                    <!--                                    </el-form-item>-->
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="10">
                                    <el-form-item label="考试城市">
                                        <el-select v-model="form.exam_city" placeholder="请选择证件类型">
                                            <!--                                            <el-option v-for="item in form.course.examdate" :key="item.id"-->
                                            <!--                                                       :label="item.exam_city"-->
                                            <!--                                                       :value="item.exam_city"></el-option>-->
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <el-form-item label="考试时间">
                                        <el-select v-model="form.exam_date" placeholder="请选择考试时间">
                                            <!--                                            <el-option v-for="item in form.course.examdate" :key="item.id"-->
                                            <!--                                                       :label="item.exam_date"-->
                                            <!--                                                       :value="item.exam_date"></el-option>-->
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </div>
                        <el-form-item>
                            <el-button type="primary" @click="editContent">立即修改</el-button>
                            <el-button @click="editHandleClose">取消</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-drawer>
        </div>
        <div v-if="toExamisShow" class="exam animate__animated animate__zoomIn">
            <div class="exam-header">
                <el-card>
                    <el-page-header @back="goBack" content="详情页面">
                    </el-page-header>
                </el-card>
                <el-card>
                    <el-form label-position="right" ref="examForm" :rules="rules" label-width="120px" :model="examForm">
                        <el-steps align-center :active="active" finish-status="success">
                            <el-step title="步骤 1"></el-step>
                            <el-step title="步骤 2"></el-step>
                            <el-step title="步骤 3"></el-step>
                        </el-steps>
                        <div style="padding: 20px;text-align: left;">
                            <div v-show="active == 1">
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="name" label="姓名:">
                                            <el-input v-model="examForm.name"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="last_py" label="姓拼音:">
                                            <el-input v-model="examForm.last_py"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item prop="first_py" label="名拼音:">
                                            <el-input v-model="examForm.first_py"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="证件类型:">
                                            <el-select v-model="examForm.card_type" placeholder="请选择证件类型">
                                                <el-option v-for="item in cardOptions" :key="item.id" :label="item.name"
                                                           :value="item.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="9">
                                        <el-form-item label="证件号码:">
                                            <el-input v-model="examForm.card_id"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="出生日期:">
                                            <el-date-picker format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"
                                                            placeholder="选择日期" v-model="examForm.birthday"
                                                            style="width: 100%;"></el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="家庭住址:">
                                            <el-input type="textarea" autosize v-model="examForm.address"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="school" label="毕业学校:">
                                            <el-input v-model="examForm.school"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="9">
                                        <el-form-item prop="grad_time" label="毕业时间:">
                                            <el-date-picker format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"
                                                            placeholder="选择日期" v-model="examForm.grad_time"
                                                            style="width: 100%;"></el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="hig_edu" label="最高学历:">
                                            <el-select v-model="examForm.hig_edu" placeholder="最高学历">
                                                <el-option label="硕士研究生" value="硕士研究生"></el-option>
                                                <el-option label="博士" value="博士"></el-option>
                                                <el-option label="本科" value="本科"></el-option>
                                                <el-option label="大专" value="大专"></el-option>
                                                <el-option label="中专/职技校" value="中专/职技校"></el-option>
                                                <el-option label="高中" value="高中"></el-option>
                                                <el-option label="其他" value="其他"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="9">
                                        <el-form-item prop="major" label="专业门类:">
                                            <el-input v-model="examForm.major"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </div>
                            <div v-show="active == 2">
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="单位名称:">
                                            <el-input v-model="examForm.com_name"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item prop="work_duty" label="现有职务:">
                                            <el-input v-model="examForm.work_duty"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="现有职务英文:">
                                            <el-input v-model="examForm.work_duty_en"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item prop="work_title" label="现有职称:">
                                            <el-input v-model="examForm.work_title"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="work_age" label="从业年限:">
                                            <el-input type="number" v-model="examForm.work_age"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </div>
                            <div v-show="active == 3">
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item label="机构:">
                                            <el-input v-model="examForm.org.org_code"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <!--                                    <el-col :span="8">-->
                                    <!--                                        <el-form-item prop="course" label="考试级别:">-->
                                    <!--                                            <el-input v-model="examForm.course.id"></el-input>-->
                                    <!--                                        </el-form-item>-->
                                    <!--                                    </el-col>-->
                                    <el-col :span="9">
                                        <el-form-item prop="exam_date" label="考试时间:">
                                            <el-select v-model="examForm.exam_date" placeholder="请选择考试时间">
                                                <el-option v-for="item in examForm.course.examdate" :key="item.id"
                                                           :label="item.exam_date"
                                                           :value="item.exam_date"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="exam_city" label="考试城市:">
                                            <el-select v-model="examForm.exam_city" placeholder="请选择证件类型">
                                                <el-option v-for="item in examForm.course.examdate" :key="item.id"
                                                           :label="item.exam_city"
                                                           :value="item.exam_city"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item style="text-align: left" label="是否参加培训:">
                                            <el-switch
                                                    v-model="examForm.is_train"
                                                    active-color="#13ce66">
                                            </el-switch>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col>
                                        <el-form-item label="证件照:">
                                            <!--                                            <card-upload ref="cardUpload"></card-upload>-->
                                            <img-upload :url="examForm.photo" @upload="upload"></img-upload>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col>
                                        <el-form-item label="电子签名:">
                                            <el-input v-model="examForm.sign"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row :gutter="20">
                                    <el-col :span="8">
                                        <el-form-item prop="phone" label="手机号码:">
                                            <el-input v-model="examForm.phone"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="10">
                                        <el-form-item prop="code" label="短信验证码">
                                            <div style="display: flex;">
                                                <el-input v-model="examForm.code"></el-input>
                                                <el-button>
                                                    <tencent-captcha ref="captcha" :phone-rule="phoneRule"
                                                                     :phone="examForm.phone"
                                                                     scene="2"></tencent-captcha>
                                                </el-button>
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </div>
                        </div>
                    </el-form>
                    <el-button v-if="active > 1 && active < 4" style="margin-top: 12px;" @click="pre">上一步</el-button>
                    <el-button v-if="active < 3" style="margin-top: 12px;" @click="next">下一步</el-button>
                    <el-button v-if="active == 3" style="margin-top: 12px;" @click="examReg">提交</el-button>
                </el-card>
            </div>
        </div>
    </div>
</template>

<script>
    import registerForm from "../../../components/registerForm/registerForm";
    import {provinceAndCityData, CodeToText, TextToCode} from 'element-china-area-data'
    import {getProfile, exam_reg, get_n_Org, editContent, courselist} from "../../../request/api";
    import TencentCaptcha from "../../../components/TencentCaptcha/TencentCaptcha";
    import imgUpload from "../../../components/imgUpload/imgUpload";
    import 'animate.css'
    import '../../../assets/icon/iconfont.css'

    export default {
        name: "mainComponent",
        data() {
            var phoneRule = (rule, value, callback) => {
                let phoneRule = /^1[23456789]\d{9}$/;
                if (value === '') {
                    callback(new Error('请输入手机号码'));
                    this.phoneRule = false;
                } else if (!phoneRule.test(value)) {
                    callback(new Error('手机号码格式错误'))
                    this.phoneRule = false;
                } else {
                    this.phoneRule = true;
                    callback();
                }
            };
            return {
                drawer: false,
                direction: 'rtl',
                registerVisible: false,
                person: {},//个人信息对象
                active: 1,
                profile: [],//档案数组
                cardOptions: [{id: 1, name: '居民身份证'}, {id: 2, name: '护照'}, {id: 3, name: '港澳台胞身份证'}],
                toExamisShow: false,
                rules: {
                    name: [
                        {required: true, message: '请输入用户名', trigger: 'blur'},
                    ],
                    last_py: [
                        {required: true, message: '请输入姓拼音', trigger: 'blur'}
                    ],
                    first_py: [
                        {required: true, message: '请输入名拼音', trigger: 'blur'}
                    ],
                    card_type: [
                        {required: true, message: '请选择证件类型', trigger: 'change'}
                    ],
                    card_id: [
                        {required: true, message: '请输入证件号码', trigger: 'blur'}
                    ],
                    birthday: [
                        {
                            required: true, message: '请输入出生年月', trigger: 'blur'
                        }
                    ],
                    address: [
                        {
                            required: true, message: '请输入家庭住址', trigger: 'blur'
                        }
                    ],
                    org_code: [
                        {required: true, message: '请输入机构代码', trigger: 'blur'}
                    ],
                    school: [
                        {required: true, message: '请输入学校名称', trigger: 'blur'}
                    ],
                    grad_time: [
                        {required: true, message: '请填写毕业时间', trigger: 'change'}
                    ],
                    hig_edu: [
                        {required: true, message: '请填写最高学历', trigger: 'blur'}
                    ],
                    major: [
                        {required: true, message: '请输入专业门类', trigger: 'blur'}
                    ],
                    com_name: [
                        {required: true, message: '请输入单位名称', trigger: 'blur'}
                    ],
                    work_duty: [
                        {required: true, message: '请输入现有职务', trigger: 'blur'}
                    ],
                    work_title: [
                        {required: true, message: '请输入现有职称', trigger: 'blur'}
                    ],
                    work_age: [
                        {required: true, message: '请填写从业年限', trigger: 'change'}
                    ],
                    course: [
                        {required: true, message: '请输入考试级别', trigger: 'blur'}
                    ],
                    exam_date: [
                        {required: true, message: '请填写考试时间', trigger: 'change'}
                    ],
                    exam_city: [
                        {required: true, message: '请填写考试城市', trigger: 'change'}
                    ],
                    is_train: [
                        {required: true, message: '请选择是否参加培训', trigger: 'change'}
                    ],
                    photo: [
                        {required: true, message: '请上传证件照', trigger: 'blur'}
                    ],
                    phone: [
                        {validator: phoneRule, trigger: 'blur'}
                    ],
                    code: [
                        {required: true, message: '请输入手机验证码', trigger: 'blur'}
                    ]
                },
                examForm: {
                    name: '',//姓名
                    last_py: '',//姓拼音
                    first_py: '',//名拼音
                    card_type: 1,//证件类型
                    card_id: '',//证件号码
                    birthday: '',//出生日期
                    address: '',//家庭住址
                    org: {
                        org_code: '',//机构代码
                    },
                    school: '',//毕业学校
                    grad_time: '',//毕业时间
                    hig_edu: '',//最高学历
                    major: '',//专业门类
                    com_name: '',//单位名称
                    work_duty: '',//现有职务
                    work_duty_en: '',//现有职务英文
                    work_title: '',//现有职称
                    work_age: '1',//从业年限
                    course: {
                        id: '', //考试级别,
                        name: ''
                    },
                    exam_date: '',//考试时间
                    exam_city: '',//考试城市 (薪酬管理师)
                    is_train: false,//是否参加培训 (薪酬管理师)
                    photo: "",//上传证件照片
                    sign: '',//电子签名
                    phone: '',//手机号码
                    code: '',//手机验证码
                },
                form: {},
                oldForm: {},
                areaOptions: provinceAndCityData,//省市区三级联动
                selectedOptions: [],//选择后的省市区对象数组
                courseList: [],
                phoneRule: false,
                state_map: {
                    0: '机构一审驳回',
                    1: '机构一审待审',
                    2: '机构一审待审',
                    3: '总部一审待审',
                    4: '总部一审待审',
                    5: '机构二审待审',
                    6: '机构二审待审',
                    7: '总部二审待审',
                    8: '全部审核通过'
                }
            }
        },
        methods: {
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {

            },
            goBack() {
                console.log('返回');
                this.toExamisShow = false;
            },
            toExam(profile_id) {
                this.active = 1;
                this.toExamisShow = true;
                console.log('profile_id', profile_id);
                for (let item of this.profile) {
                    if (item.id === profile_id) {
                        this.examForm = item
                    }
                }
                console.log('this.examForm', this.examForm)
            },
            upload(photo) {
                this.examForm.photo = photo;
            },
            updateUpload(photo) {
                this.form.photo = photo;
            },
            pre() {
                if (this.active-- < 2) this.active = 1
            },
            next() {
                if (this.active++ > 3) this.active = 1;
            },
            getProfile() {
                getProfile().then(res => {
                    console.log(res)
                    this.profile = res;
                    for (let item of res) {
                        if (item.state_code > 7) {
                            this.person = item;
                            return
                        }
                    }
                    this.person = res[length - 1];
                    console.log('this.person', this.person)
                })
            },
            examReg() {
                this.$refs['examForm'].validate((valid) => {
                    if (valid) {
                        this.examForm['course_id'] = this.examForm.course.id;
                        this.examForm['org_code'] = this.examForm.org.org_code;
                        console.log(this.examForm);
                        exam_reg(this.examForm).then(res => {
                            console.log(res);
                            this.$message({
                                type: "success",
                                message: "提交成功"
                            })
                            this.toExamisShow = false;
                            this.getProfile();

                        }).catch(err => {
                            this.$refs['captcha'].isShow = true
                            console.log('catch', err)
                            this.$message({
                                type: 'error',
                                message: err.msg + err.errors
                            })
                        })
                    } else {
                        this.$message({
                            type: "warning",
                            message: "请检查是否漏写字段"
                        })
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            ExamhandleClose(done) {
                console.log('修改关闭');
                this.getProfile();
                done();
            },
            updateExam(exam_id) {
                this.drawer = true
                console.log(exam_id);
                for (let item of this.profile) {
                    if (item.id == exam_id) {
                        this.form = JSON.parse(JSON.stringify(item))
                        this.selectedOptions.push(TextToCode[this.form.province].code,TextToCode[this.form.province][this.form.city].code);
                        this.oldForm = JSON.parse(JSON.stringify(this.form))
                    }
                }
                console.log('exam_id', exam_id)
            },
            //获取省市区
            addressChange(arr) {
                this.form.province = CodeToText[arr[0]];
                this.form.city = CodeToText[arr[1]];
            },
            //N次报名
            get_n_Org(params) {
                console.log('params', params)
                get_n_Org(params).then(res => {
                    console.log(res);
                    this.registerVisible = false;
                    this.getProfile();
                }).catch(err => {
                    this.$message({
                        type: 'error',
                        message: err.msg
                    })
                })
            },
            addRegisterClose(done) {
                done();
            },
            //修改信息
            editContent() {
                console.log('oldForm', this.oldForm, 'newForm', this.form);
                let params = {'pid': this.form.id};
                for (let item in this.oldForm) {
                    if (this.form[item] !== this.oldForm[item]) {
                        if (Object.prototype.toString.call(this.form[item]) === '[object Object]') {
                            continue;
                        }
                        params[item] = this.form[item];
                    }
                }
                let cardObj = {
                    card_id:this.form.card_id,
                    card_type:this.form.card_type,
                    name:this.form.name
                }
                for (let key in params){
                    if(cardObj.hasOwnProperty(key)){
                        Object.assign(params,cardObj)
                    }
                }
                console.log('params', params)
                editContent(params).then(res => {
                    console.log(res);
                    this.$message({
                        type: "success",
                        message: "修改成功"
                    })
                    this.drawer = false;
                    this.getProfile();
                }).catch(err => {
                    let resetForm = JSON.parse(JSON.stringify(this.oldForm))
                    this.form = resetForm;
                    this.person = this.oldForm;
                    this.$message({
                        type: "error",
                        message: err.msg
                    })
                })
            },
            //取消
            editHandleClose() {
                this.drawer = false;
                this.getProfile();
            },
            //获取考试城市列表(薪酬管理师)
            CourseList() {
                courselist().then(res => {
                    let arr = []
                    for (let item of res) {
                        for (let item2 of item.examdate) {
                            arr.push(item2['exam_city'])
                        }
                    }
                    this.courseList = arr
                    console.log('this.courseList', this.courseList);
                })
            }
        },
        computed:{
            userDisable(){
                if(this.form.state_code >= 4 && this.oldForm.card_type == 1){
                    return true
                }
                return false
            }
        },
        created() {
            this.getProfile();
            this.CourseList();
        },
        components: {
            imgUpload,
            TencentCaptcha,
            registerForm
        }
    }
</script>

<style>
    .el-avatar--square {
        border: 0.5px solid gray;
    }

    ::-webkit-scrollbar {
        width: 0px;
        height: 0px;
    }
</style>

<style scoped>
    .exam-text {
        line-height: 24px;
    }

    .person-address {
        text-align: left;
        padding: 10px 0px;
    }

    .exam-header {
        width: 100%;
    }

    .exam-content {
        margin-bottom: 10px;
    }

    .right-content {
        text-align: left;
    }

    .school-content {
        display: flex;
        margin-bottom: 10px;
    }

    .school-content p {
        text-align: left;
        margin: 10px 0px;
    }

    .person-content {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    .person-content p {
        text-align: left;
        margin-left: 20px;
        padding: 5px 0px;
    }

    .content {
        width: 100%;
    }

    .box-card {
        width: 100%;
    }

    .user-main {
        width: 1180px;
        height: calc(100vh - 80px);
        margin: 0 auto;
        padding: 10px;
        display: flex;
        justify-content: space-between;
    }

    .exam {
        width: 1180px;
        height: calc(100vh - 80px);
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        background-color: #008B8B;
    }
</style>
